package ioParation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnParatiom implements  IoParation {
    public void work(BookList bookList) {
        System.out.println("正在归还图书中。。。。。");
        System.out.println("请输入要归还书本的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int cuurentSized = bookList.getUsedSized();

        //1.判断是否借出
        for (int i = 0; i < cuurentSized; i++) {
            Book book = bookList.getBook(i);
            //1.书名相同
            if (book.getName().equals(name)) {
                //2.已经被借出了
                if (book.isBorrowed()) {
                    book.setBorrowed(false);
                    System.out.println("归还成功");
                    return;
                }
            }
         }
        System.out.println("没有你需要归还的书本");
    }
}